package com.myidis.mapper;

import java.util.ArrayList;
import java.util.List;

import com.myidis.entity.QuotaData;
import com.myidis.request.SearchReq;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import com.myidis.entity.QuotaList;

public interface QuotaQueryMapper {
//	@Select("SELECT distinct chinese_name FROM idis.quota where type;")
//	@Results({
//		@Result(property = "name", column = "quota"),
//		@Result(property = "item", column = "chinese_name")
//	}) 
//	List<QuotaList> selectQuotaName();

	@Select("SELECT distinct chinese_name FROM idis.quota where type = #{type} AND chinese_name like #{name};")
	@Results({
		@Result(property = "name", column = "chinese_name")
	})
	ArrayList<QuotaList> getByName(@Param("type")String type, @Param("name")String name);

	@Select("SELECT distinct dataitem,quota FROM idis.quota_data WHERE quota = #{keyWord1}")
	@Results({
		@Result(property = "name", column = "quota"),
		@Result(property = "item", column = "dataitem")
	})
	ArrayList<QuotaList> getDataItems(SearchReq sea);

    @Select("SELECT * FROM idis.quota_data WHERE time BETWEEN #{keyWord1} AND #{keyWord2}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "frequency", column = "frequency"),
            @Result(property = "time", column = "time"),
            @Result(property = "quota", column = "quota"),
            @Result(property = "dataItem", column = "dataitem"),
            @Result(property = "value", column = "value"),
            @Result(property = "unit", column = "unit")
    })
	ArrayList<QuotaData> searchByTime(SearchReq sea);

	@Select("SELECT * FROM quota_data WHERE frequency = #{keyNum2} and dataitem = #{keyNum1} and " +
            "quota = #{condition} and time BETWEEN #{time1} AND #{time2}")
	@Results({
		@Result(property = "time", column = "time"),
		@Result(property = "value", column = "value")
	})
	ArrayList<QuotaData> getOne(SearchReq sea);

	@Insert("INSERT into quota_data (frequency, time, quota, dataitem, value, unit) " +
			"VALUES (#{frequency}, #{time}, #{quota}, #{dataItem}, #{value}, #{unit} ) ")
	int insert(QuotaData ins);

    @Update("UPDATE quota_data SET value = #{value} WHERE time = #{time} and dataitem = #{dataItem} " +
            "and quota = #{quota} and frequency = #{frequency};")
    int update(QuotaData cha);

    @Delete("DELETE FROM monthQuotaList WHERE id = #{id}")
    int delete(int id);

}
